#!/bin/bash
source /etc/profile

start () {
    cd /data/htdocs/grafana/
    ./bin/grafana-server > /data/logs/grafana.log 2>&1 &
    sleep 3
    [ -n $(ps aux|grep grafana|grep server|grep -v grep|awk '{print $2}') ] && echo "start grafana success"
}

stop () {
    grafana_pid=$(ps aux|grep grafana|grep server|grep -v grep|awk '{print $2}')
    kill -9 ${grafana_pid}
    echo "stop grafana success"
}

case $1 in
    start)
        start;;
    stop)
        stop;;
    restart)
        stop
        sleep 2
        start;;
    *)
        echo "Usage: ./grafana start|stop|restart";;
esac
